package com.xuwang.controller;

import com.xuwang.pojo.Stock;
import com.xuwang.service.impl.StockServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.util.Map;

/**
 * 进货表（菜品、原料、添加剂都在这里面）(Stock)表控制层
 *
 * @author abaaba
 * @since 2021-09-18 14:18:01
 * @version 1.0
 */
@RestController
@RequestMapping("/stock")
@Api(value = "进货表（菜品、原料、添加剂都在这里面）(Stock)管理",tags = "进货表（菜品、原料、添加剂都在这里面）(Stock)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class StockController {
    /**
     * 服务对象
     */
    @Resource
    private StockServiceImpl stockServiceImpl;
    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
//     * @param name  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageZF", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "每页数量",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "batchNo",value = "生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "name",value = "进货物名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "type",value = "货物类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "starTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "warranty",value = "保质期",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "supplyCompanyName",value = "供货公司名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "receiveCompanyName",value = "接收公司名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageZF(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,String name,
                                               String batchNo, String type, String starTime, String endTime, Integer warranty, String supplyCompanyName,
                                               String receiveCompanyName, @Autowired HttpServletRequest request) {
        return this.stockServiceImpl.selectForPage(1,index, page,name,batchNo,type,starTime,endTime,warranty,supplyCompanyName,receiveCompanyName,request);
    }



    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageQYGH", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "每页数量",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "name",value = "进货物名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "batchNo",value = "生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "type",value = "货物类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "starTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "warranty",value = "保质期",paramType = "query",dataType = "String",required = false),
//            @ApiImplicitParam(name = "supplyCompanyName",value = "供货公司名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "receiveCompanyName",value = "接收公司名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageQYGH(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,String name,
                                               String batchNo, String type, String starTime, String endTime, Integer warranty,
                                               String receiveCompanyName, @Autowired HttpServletRequest request) {
        return this.stockServiceImpl.selectForPage(2,index, page,name,batchNo,type,starTime,endTime,warranty,null,receiveCompanyName,request);
    }

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPageQYJH", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "index",value = "第几页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "每页数量",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "name",value = "进货物名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "batchNo",value = "生产批号",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "type",value = "货物类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "starTime",value = "开始时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "endTime",value = "结束时间",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "warranty",value = "保质期",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "supplyCompanyName",value = "供货公司名称",paramType = "query",dataType = "String",required = false)
//            @ApiImplicitParam(name = "receiveCompanyName",value = "接收公司名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectForPageQYJH(@RequestParam(name = "index") int index, @RequestParam(name = "page") int page,String name,
                                               String batchNo, String type, String starTime, String endTime, Integer warranty, String supplyCompanyName,
                                              @Autowired HttpServletRequest request) {
        return this.stockServiceImpl.selectForPage(3,index, page,name,batchNo,type,starTime,endTime,warranty,supplyCompanyName,null,request);
    }
//    /**
//     * 查询所有数据
//     * @return 返回所有数据
//     */
//    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
//    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
//    public Map<String, Object> selectAll() {
//        return this.stockServiceImpl.selectAll();
//    }
//

    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个**的接口",notes = "通过主键查询一个**的接口",httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.stockServiceImpl.selectById(id);
    }


    @RequestMapping(value = "/selectAllCompany", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有公司的id",notes = "查询所有公司的id",httpMethod = "GET")
    public Map<String, Object> selectAllCompany(@Autowired HttpServletRequest request) {
        return this.stockServiceImpl.selectAllCompany(request);
    }

//    /**
//     * 通过主键更新单条数据
//     *
//     * @param stock 一个数据库对应的POJO数据对象
//     * @return 单条数据
//     */
//    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
//    @ApiOperation(value = "通过主键更新一个**的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
//    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "stock",value = "pojo模型",required = true) Stock stock) {
//        return this.stockServiceImpl.updateById(stock);
//    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param stock 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @Transactional
    @RequestMapping(value = "/insertJH", method = RequestMethod.POST)
    @ApiOperation(value = "进货,传递批号、检查人、数量",notes = "进货接口",httpMethod = "POST")
    public Map<String, Object> insertJH(@RequestBody @ApiParam(name = "stock",value = "pojo模型",required = true) Stock stock,@Autowired HttpServletRequest request) {
        return this.stockServiceImpl.insert(stock,1,request);

    }
    @Transactional
    @RequestMapping(value = "/insertGH", method = RequestMethod.POST)
    @ApiOperation(value = "供货，传递批号、检查人、数量、接受公司的id",notes = "供货接口",httpMethod = "POST")
    public Map<String, Object> insertGH(@RequestBody @ApiParam(name = "stock",value = "pojo模型",required = true) Stock stock,@Autowired HttpServletRequest request) {
        return this.stockServiceImpl.insert(stock,2,request);
    }

}